//
//  MBSpaceGradeDescribeCell.m
//  MiBaoTu
//
//  Created by admin on 16/9/21.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceGradeDescribeCell.h"

@interface MBSpaceGradeDescribeCell () {
    UIImageView                 *_userImgView;
    UILabel                     *_nickNameLb;
    UILabel                     *_gradeLb;
    UIView                      *_lineView;
}

@end
@implementation MBSpaceGradeDescribeCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self onCreateUI];
    }
    return self;
}

- (void)onCreateUI
{
    //头像
    _userImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _userImgView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_userImgView];
    
    //昵称
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentLeft;
    _nickNameLb.textColor = UIColorFromHex(0x333333);
    _nickNameLb.font = [UIFont systemFontOfSize:13.f];
    [self.contentView addSubview:_nickNameLb];
    
    //等级
    _gradeLb = [[UILabel alloc]initWithFrame:CGRectZero];
    _gradeLb.backgroundColor = [UIColor clearColor];
    _gradeLb.textAlignment = NSTextAlignmentLeft;
    _gradeLb.textColor = UIColorFromHex(0x999999);
    _gradeLb.font = [UIFont systemFontOfSize:11.f];
    [self.contentView addSubview:_gradeLb];
    
    //线
    _lineView = [[UIView alloc]initWithFrame:CGRectZero];
    _lineView.backgroundColor = [UIColorFromHex(0x999999) colorWithAlphaComponent:.15];
    [self.contentView addSubview:_lineView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOrientation:(UIDeviceOrientation)orientation
{
    _orientation = orientation;
    [self setNeedsLayout];
}

- (void)setScriptStr:(NSString *)scriptStr
{
    _scriptStr = scriptStr;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //value
    UIImage *img = [UIImage imageNamed:@"qiandao"];
    _userImgView.image = img;
    
    if (_scriptStr.length > 0) {
        _nickNameLb.text = _scriptStr;
    } else {
        _nickNameLb.text = @"播放歌曲";
    }
//    _gradeLb.text = [NSString stringWithFormat:@"剩余%@次",@"3"];
    
    //frame
    _userImgView.frame = CGRectMake((ISIPAD?460*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), (self.height-img.size.height)/2., img.size.width, img.size.height);
    
    float nickWidth = [_nickNameLb.text boundingRectWithSize:CGSizeMake(1000, 20) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:_nickNameLb.font} context:NULL].size.width+4;
    _nickNameLb.frame = CGRectMake(_userImgView.right+10*PERCEN, (self.height-20)/2., nickWidth, 20);
    
    _gradeLb.frame = CGRectMake(_nickNameLb.right+10*PERCEN, _nickNameLb.top, 120, 20);
    
    _lineView.frame = CGRectMake((ISIPAD?440*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):25*PERCEN), self.height-1, (ISIPAD?SCREEN_WIDTH-880*PERCEN*(_orientation==UIDeviceOrientationPortrait?1.0*SCREEN_WIDTH/SCREEN_HEIGHT:1.):self.width-25*PERCEN), 1);
}

@end
